/*
 * Copyright (C) 2018 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.xuexiang.xdlink.core;

import android.support.annotation.NonNull;

import com.xuexiang.xdlink.component.command.IProtocolCommand;
import com.xuexiang.xdlink.component.message.IRequestMessage;

/**
 * 设备连接中心
 *
 * @author xuexiang
 * @since 2018/8/20 下午11:35
 */
public interface IDeviceConnectCenter {

    /**
     * 连接设备
     */
    void connectDevice();

    /**
     * 断开设备连接
     */
    void disConnectDevice();

    /**
     * 发送请求消息
     *
     * @param message 请求消息
     * @return {@code true} : 发送成功 <br> {@code false} : 发送失败
     */
    boolean sendMessage(@NonNull IRequestMessage message);

    /**
     * 调用IProtocol协议命令，由设置的协议处理【IProtocolCommand -> IMessage -> 下抛】
     *
     * @param command
     */
    void executeCommand(IProtocolCommand command);

    //================对外API===================//

    /**
     * @return 通信通道是否开启
     */
    boolean isChannelOpen();

    /**
     * 重新打开通信通道
     */
    void reOpenChannel();

    /**
     * @return 获取重新打开通道的次数
     */
    int getReOpenCount();

    /**
     * 开启设备监控器
     */
    void startMonitor();

    /**
     * 停止设备监控器
     */
    void stopMonitor();

    /**
     * @return 设备监控器是否在运行
     */
    boolean isMonitorRunning();

    /**
     * 切换数据保存的状态
     *
     * @param isTurnOn 是否保存数据
     */
    void switchDataSaveStatus(boolean isTurnOn);

    /**
     * 取消数据保存，删除已保存的数据文件
     */
    boolean cancelDataSave();

    /**
     * @return 获取设备的类型
     */
    String getDeviceType();

    /**
     * @return 判断设备是否接收到数据
     */
    boolean hasReceivedData();

}
